import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:photo_manager/photo_manager.dart';
import 'package:wechat_assets_picker/wechat_assets_picker.dart';

//不带相机的
Future<List<AssetEntity>> pickAsset(
  BuildContext context,
  RequestType requestType, {
  List<AssetEntity> assets,
  int length = 0,
  bool isShowCropEditer = true,
  int maxAssetsCount = 9,
  bool isCanEdite = true,
}) async {
  final bool isPermissionGranted = await PhotoManager.requestPermission();
  if (isPermissionGranted) {
    return await AssetPicker.pickAssets(
      context,
      maxAssets: maxAssetsCount - length,
      selectedAssets: assets,
      isShowCorpEditer: isShowCropEditer,
      requestType: requestType,
      isCanEdite: isCanEdite,
    );
  }

  return await AssetPicker.pickAssets(
    context,
    maxAssets: maxAssetsCount - length,
    selectedAssets: assets,
    isShowCorpEditer: isShowCropEditer,
    requestType: requestType,
  );
}

//不带相机的
Future<List<AssetEntity>> pickAssetCamera(
  BuildContext context,
  RequestType requestType, {
  List<AssetEntity> assets,
  int length = 0,
  bool isShowCropEditer = true,
  int maxAssetsCount = 9,
}) async {
  Map<Permission, PermissionStatus> statuses = await [
    Permission.camera,
    Permission.storage,
  ].request();

  if (statuses[Permission.camera].isGranted &&
      statuses[Permission.storage].isGranted) {
    return await AssetPicker.pickAssetsAnCamera(
      context,
      maxAssets: maxAssetsCount - length,
      selectedAssets: assets,
      isShowCorpEditer: isShowCropEditer,
      requestType: requestType,
    );
  }

  return await AssetPicker.pickAssetsAnCamera(
    context,
    maxAssets: maxAssetsCount - length,
    selectedAssets: assets,
    isShowCorpEditer: isShowCropEditer,
    requestType: requestType,
  );
}
